# Contributor: Bart Ribbers <bribbers@disroot.org>
# Maintainer: Bart Ribbers <bribbers@disroot.org>
pkgname=libavif
pkgver=1.0.4
pkgrel=0
pkgdesc="Library for encoding and decoding .avif files"
url="https://aomediacodec.github.io/av1-avif/"
arch="all"
license="BSD-2-Clause"
makedepends="
	aom-dev
	cmake
	dav1d-dev
	gdk-pixbuf-dev
	gtest-dev
	libjpeg-turbo-dev
	libpng-dev
	samurai
	zlib-dev
	"
subpackages="$pkgname-dev $pkgname-apps $pkgname-pixbuf-loader"
source="https://github.com/AOMediaCodec/libavif/archive/v$pkgver/libavif-v$pkgver.tar.gz"

build() {
	CFLAGS="$CFLAGS -flto=auto" \
	CXXFLAGS="$CXXFLAGS -flto=auto" \
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=RelWithDebInfo \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DAVIF_BUILD_APPS=ON \
		-DAVIF_BUILD_GDK_PIXBUF=ON \
		-DAVIF_BUILD_TESTS=ON \
		-DAVIF_CODEC_AOM=ON \
		-DAVIF_CODEC_DAV1D=ON
	cmake --build build
}

check() {
	# cmake --build build --target avif_test_all

	# https://github.com/AOMediaCodec/libavif/issues/800
	cd "$builddir"/build
	./tests/aviftest ../tests/data --io-only
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

apps() {
	amove usr/bin
}

loader() {
	pkgdesc="$pkgdesc (pixbuf loader)"
	install_if="$pkgname=$pkgver-r$pkgrel gdk-pixbuf-loaders"

	amove \
		usr/lib/gdk-pixbuf-* \
		usr/share/thumbnailers
}

sha512sums="
37f0de757180c6414778e688006940395960b316c25192d6beb97a07942aff4bd3b712dec2eff52cd26f5d72c352731442175dfeb90e2e1381133539760142b0  libavif-v1.0.4.tar.gz
"
